import React, { useEffect, useState } from 'react'
import { View,Image, Text, Input } from '@tarojs/components'
import Taro from '@tarojs/taro'

import './index.scss'

export default function WatchAdd() {
  const [query,setQuery] = useState({})
  function handleToNotice(){
    Taro.navigateTo({
      url:'/pages/other/name-notice/index'
    })
  }
  function handleSubmit(){
    const data = {
      "idCardNo": query.idCardNo,
      "realName": query.realName
    }
    if(!data.realName){
      Taro.$toast('请先输入姓名')
      return;
    }
    if(!data.idCardNo){
      Taro.$toast('请先输入证件号码')
      return;
    }
    Taro.showModal({
      title:'新增观影人',
      content:'是否新增观影人',
      success:async res=>{
        if(res.confirm){
          const res = await Taro.$post('/act/user-certification',data,'1')
          if(res.code == '1'){
            Taro.$toast('提交成功','success')
            setTimeout(()=>{
              Taro.navigateBack()
            },1000)
          }else{
            Taro.$toast(res.message)
          }
        }
      }
    })
  }
  return (
    <View className="watch-add">
      <View className="add-list">
        <View className="list-item">
          <View className="item-p">姓名</View>
          <Input className="input" type="text" onInput={e=>{
            setQuery({...query,realName:e.target.value})
          }} placeholder="请填写观演人姓名" />
        </View>
        <View className="list-item">
          <View className="item-p">证件类型</View>
          <View className='p'>身份证</View>
        </View>
        <View className="list-item">
          <View className="item-p">证件号码</View>
          <Input className="input" type="text" onInput={e=>{
            setQuery({...query,idCardNo:e.target.value})
          }} placeholder="请填写证件号码" />
        </View>
      </View>
      <View className="add-info">
        <Image src={require('@/static/info-full.svg')} mode="widthFix" style="width: 32rpx;height:32rpx"></Image>
        点击确定表示您已阅读并同意<Text className="span" onClick={()=>{handleToNotice()}}>《实名须知》</Text>
      </View>
      <View className="add-footer">
        <View className="footer-button" onClick={()=>{handleSubmit()}}>确定</View>
      </View>
    </View>
  )
}
